package com.fs.ibox.web;

import com.fs.ibox.pojo.Botice;
import com.fs.ibox.service.BoticeService;
import com.fs.ibox.util.BeanFactory;
import com.fs.ibox.util.ResponseDataUtil;
import com.fs.ibox.util.ResponseJSONUtil;
import com.fs.ibox.vo.ResponseData;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "BoticeServlet", value = "/BoticeServlet/*")
public class BoticeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=UTF-8");
        String path = request.getPathInfo();
        if ("/show".equals(path)){
            show(request,response);
        }

    }

    private void show(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String type = request.getParameter("type");
        int inttype=Integer.parseInt(type);
        BoticeService bean = BeanFactory.createBean(BoticeService.class);
        List<Botice> botices = bean.qAll(inttype);
        ResponseData responseData = ResponseDataUtil.buildOk(botices);
        ResponseJSONUtil.responseJSON(responseData,response);
    }
}
